﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using lcs.Model;
namespace lcs.BLL
{
    /// <summary>
    /// out_storage_detail
    /// </summary>
    public partial class out_storage_detail
    {
        private readonly lcs.DAL.out_storage_detail dal = new lcs.DAL.out_storage_detail();
        public out_storage_detail()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int out_storage_detail_Id)
        {
            return dal.Exists(out_storage_detail_Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(lcs.Model.out_storage_detail model)
        {
            return dal.Add(model);
        }
        public bool UpdatePic(int out_storage_detail_Id, string file)
        {
            return dal.UpdatePic(out_storage_detail_Id, file);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(lcs.Model.out_storage_detail model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int out_storage_detail_Id)
        {
            Model.out_storage_detail model = dal.GetModel(out_storage_detail_Id);
            if (model.jd == null)
            {
                DAL.fmmateriallink fbll = new DAL.fmmateriallink();
                fbll.Deleteosdid(out_storage_detail_Id);
                return dal.Delete(out_storage_detail_Id);
            }
            else
                return false;
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string out_storage_detail_Idlist)
        {
            return dal.DeleteList(out_storage_detail_Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lcs.Model.out_storage_detail GetModel(int out_storage_detail_Id)
        {

            return dal.GetModel(out_storage_detail_Id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public lcs.Model.out_storage_detail GetModelByCache(int out_storage_detail_Id)
        {

            string CacheKey = "out_storage_detailModel-" + out_storage_detail_Id;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(out_storage_detail_Id);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (lcs.Model.out_storage_detail)objModel;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListByVout_storage_detail_materialinfo(string strWhere)
        {
            return dal.GetListByVout_storage_detail_materialinfo(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        public DataSet GetListTZ(string strWhere)
        {
            return dal.GetListTZ(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<lcs.Model.out_storage_detail> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<lcs.Model.out_storage_detail> DataTableToList(DataTable dt)
        {
            List<lcs.Model.out_storage_detail> modelList = new List<lcs.Model.out_storage_detail>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                lcs.Model.out_storage_detail model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod
        public bool Updateuid(int uid, string ids)
        {
            if (uid != 0)
                return dal.Updateuid(uid, ids);
            else
                return false;
        }

        /// <summary>
        /// 更改分发巡检任务的人员id，out_storage_detail表中的op_uid
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool Updateopuid(int uid, string ids)
        {
            if (uid != 0)
                return dal.Updateopuid(uid, ids);
            else
                return false;
        }
        public DataSet GetListMoney(string strWhere)
        {
            return dal.GetListMoney(strWhere);
        }
        public bool UpdateEx(lcs.Model.out_storage_detail model)
        {
            return dal.UpdateEx(model);
        }
        #endregion  ExtensionMethod
    }
}

